package com.mijie.homi.search.service.index;
 
//com.mijie.homi.search.service.index.clr.start()
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import m.secury.callbackItfs;
import m.secury.securyWhile;
import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.mijie.core.IBatisDao;
import com.mijie.homi.search.api.UserSearchApi;
import com.mijie.homi.search.util.MyAnnotation;
@SuppressWarnings({"unchecked","unused"})
@Component(value="ClrRecently") 

public class ClrRecently extends clr {

	/**
	 * @param args
	 */
	@MyAnnotation()
	public static void main(String[] args) {
		UserSearchApi.iniProxool();

		ClrRecently c = (ClrRecently) UserSearchApi.getbean("ClrRecently");
		// List<Map> li = .selectList("getRecently100", nowId);
		System.out.println(c);
		c.start();
		System.out.println("f");
		 System.exit(0);
	}
@MyAnnotation
	public void start() {
	 
		while (true) {
			int maxiD = 0;
			int minid = 0;
			int n = 0;
			List<Map> li = this.selectList("getRecently100X", nowId);
			String snbt = JSONArray.fromObject(li).toString(2);
			System.out.println(snbt);
			for (Map m : li) {
				n++;
				String mid = m.get("mid").toString();
				String id = m.get("id").toString();
				Map<String, Object> parameter = new HashMap<String, Object>();
				parameter.put("id", id);
				parameter.put("mid", mid);
				parameter.put("renva", m.get("renva"));
				parameter.put("event", m.get("event"));
				Integer count = this.selectInteger("getCountByMap", parameter);
				logger.debug(" get count: mid:"+mid+" count:"+String.valueOf(count));
				if (count > 1) {
					logger.info(" get count: mid:"+mid+" count:"+String.valueOf(count));
					int r = this.update("deleteDulix", parameter);
					logger.info(" ---deleteDulix mid:"+mid+" deleSql return int:"+String.valueOf(r));
					System.out.println(r);
				}
				nowId = Integer.parseInt(id);
				if (n == 1)
					maxiD = Integer.parseInt(id);
				if (n == li.size())
					minid = Integer.parseInt(id);
			}

			Map<String, Object> parameter = new HashMap<String, Object>();
			parameter.put("maxid", maxiD);
			parameter.put("minid", minid);
			this.update("upThisLog", parameter);
		//	 break;
			 try {
			 Thread.sleep(10000);
			 } catch (InterruptedException e) {
						 
			 e.printStackTrace();
			 }
		}

	}
}

